<template>
    <el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible">
    
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="100px">
    
            <el-form-item label="项目名称" prop="projectName">
    
                <el-input v-model="dataForm.projectName" placeholder="请输入项目名称"></el-input>
    
            </el-form-item>
    
            <el-form-item label="项目描述" prop="projectDesc">
    
                <el-input v-model="dataForm.projectDesc"  type="textarea" placeholder="请输入项目描述"></el-input>
    
            </el-form-item>
    
            <el-row>
                <el-col :span="12">
                    <el-form-item label="开始日期" prop="startTime">
    
                        <el-date-picker
                        v-model="dataForm.startTime"
                        type="date"
                        value-format="yyyy-MM-dd 00:00:00"
                        placeholder="选择开始日期">
                        </el-date-picker>

                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="结束日期" prop="endTime">
                        
                        <el-date-picker
                        v-model="dataForm.endTime"
                        type="date"
                        value-format="yyyy-MM-dd 00:00:00"
                        placeholder="选择结束日期">
                        </el-date-picker>

                    </el-form-item>
                </el-col>
            </el-row>

            

            <el-form-item label="实际交付日期" prop="actualDeliveryTime">
    
                <el-date-picker
                  v-model="dataForm.actualDeliveryTime"
                  type="date"
                  value-format="yyyy-MM-dd 00:00:00"
                  placeholder="选择交付日期">
                </el-date-picker>
    
            </el-form-item>
    
            <el-form-item label="状态" size="mini" prop="status">
    
                <el-radio-group v-model="dataForm.status">
    
                    <el-radio :label="0">进行中</el-radio>
    
                    <el-radio :label="1">已完成</el-radio>
    
                </el-radio-group>
    
            </el-form-item>
    
        </el-form>
    
        <span slot="footer" class="dialog-footer">
    
          <el-button @click="visible = false">取消</el-button>
    
          <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    
        </span>
    
    </el-dialog>
</template>

<script>
import { isEmail, isMobile } from '@/utils/validate'
export default {
    data() {
        return {
            visible: false,
            roleList: [],
            dataForm: {
                id: 0,
                projectName: '',
                projectDesc: '',
                startTime: null,
                endTime: null,
                actualDeliveryTime: null,
                status: 1
            },
            dataRule: {
                projectName: [
                    { required: true, message: '项目名称不能为空', trigger: 'blur' }
                ]
            }
        }
    },
    methods: {
        init(id) {
            this.dataForm.id = id || 0
            this.visible = true
            this.$nextTick(() => {
                this.$refs['dataForm'].resetFields()
            })
            if (this.dataForm.id) {
                this.$http({
                    url: this.$http.adornUrl(`/project/plan/info/${this.dataForm.id}`),
                    method: 'get',
                    params: this.$http.adornParams()
                }).then(({ data }) => {
                    if (data && data.code === 0) {
                      console.log('===>',data)
                        this.dataForm.projectName = data.proPlan.projectName
                        this.dataForm.projectDesc = data.proPlan.projectDesc
                        this.dataForm.startTime = data.proPlan.startTime
                        this.dataForm.endTime = data.proPlan.endTime
                        this.dataForm.actualDeliveryTime = data.proPlan.actualDeliveryTime
                    }
                })
            }



        },
        // 表单提交
        dataFormSubmit() {
            this.$refs['dataForm'].validate((valid) => {
                if (valid) {
                    this.$http({
                        url: this.$http.adornUrl(`/project/plan/${!this.dataForm.id ? 'save' : 'update'}`),
                        method: 'post',
                        data: this.$http.adornData({
                            'id': this.dataForm.id || undefined,
                            'projectName': this.dataForm.projectName,
                            'projectDesc': this.dataForm.projectDesc,
                            'startTime': this.dataForm.startTime,
                            'endTime': this.dataForm.endTime,
                            'actualDeliveryTime': this.dataForm.actualDeliveryTime
                           
                        })
                    }).then(({ data }) => {
                        if (data && data.code === 0) {
                            this.$message({
                                message: '操作成功',
                                type: 'success',
                                duration: 1500,
                                onClose: () => {
                                    this.visible = false
                                    this.$emit('refreshDataList')
                                }
                            })
                        } else {
                            this.$message.error(data.msg)
                        }
                    })
                }
            })
        }
    }
}
</script>
